import math
import random  
import matplotlib.pyplot as plt
import math

# 按照分布产生随机数
# 参考: https://github.com/python/cpython/blob/main/Lib/random.py 577行
# TODO 采用公式计算的结果和原函数有微小差异

RANDOM_SEED = 42
random.seed(RANDOM_SEED)

nums = []
lambd = 1

for i in range(10000):  
    # value = random.expovariate(lambd) 

    value = random.random()
    value = - math.log(1.0 - random.random()) / lambd

    nums.append(value)

plt.hist(nums, bins = 200)  
plt.show()